package com.example.qixin0314.fragment;


import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.qixin0314.Activity.AboutUsActivity;
import com.example.qixin0314.Activity.FeedbackActivity;
import com.example.qixin0314.Activity.LlLsActivity;
import com.example.qixin0314.Activity.LoginActivity;
import com.example.qixin0314.R;
import com.example.qixin0314.Activity.SetActivity;

import cn.leancloud.LCUser;

public class mineFragment extends Fragment {
    TextView text_user;
    LCUser currentUser;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View root = inflater.inflate(R.layout.fragment_mine, container, false);
        initView(root);
        return root;

    }
    private void initView(View root){
        ImageView imageView = root.findViewById(R.id.about_me);
        ImageView log = root.findViewById(R.id.log);
        ImageView fb = root.findViewById(R.id.feedback);
        TextView set = root.findViewById(R.id.set);
        text_user=root.findViewById(R.id.text_user);
        TextView Ll_ls=root.findViewById(R.id.Ll_ls);
        currentUser = LCUser.getCurrentUser();
        if (currentUser != null) {
            text_user.setText(currentUser.getUsername());
        } else {
            text_user.setText("点击登录");
        }

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), AboutUsActivity.class);
                startActivity(intent);
            }
        });
        text_user.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentUser!=null){
                    Intent intent = new Intent(getActivity(), SetActivity.class);
                    startActivity(intent);
                }else {
                    Intent intent = new Intent(getActivity(), LoginActivity.class);
                    startActivity(intent);
                }

            }
        });
        fb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), FeedbackActivity.class);
                startActivity(intent);
            }
        });
        set.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentUser != null) {
                    Intent intent = new Intent(getActivity(), SetActivity.class);
                    startActivity(intent);
                } else {
                    Intent intent=new Intent(getActivity(),LoginActivity.class);
                    startActivity(intent);
                }

            }
        });
        Ll_ls.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentUser != null) {
                    Intent intent=new Intent(getActivity(), LlLsActivity.class);
                    startActivity(intent);
                } else {
                    Intent intent=new Intent(getActivity(),LoginActivity.class);
                    startActivity(intent);
                }
            }
        });

    }

    @Override
    public void onResume() {
        currentUser = LCUser.getCurrentUser();
        if (currentUser != null) {
            text_user.setText(currentUser.getUsername());
        } else {
            text_user.setText("点击登录");
        }
        super.onResume();
    }
}